package com.youmingxing.bean;

import com.youmingxing.utils.StringUtil;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * @author evilyin(ChenZhixi)
 * @since 15/9/12
 */
public class Content implements Serializable {
    public int id;
    public String url;
    public String thumbnail;
    public int type;//1,图片 2,视频
    public String title;
    public int u_id;
    public String u_name;
    public String u_headimg;
    public int u_apply_id;
    public String u_apply;
    public String u_apply_tip;
    public boolean u_auth;
    public String user_type;//10表示普通用户  11表示官方认证用户
    public int share_num;
    public int thumbsup_num;
    public int browse_num;
    public int status; //0待审核1审核通过2审核不通过3删除(不是必有的字段)
    public String reason; //审核不通过的原因(不是必有)


    //详情里才有的属性
    public String u_gender; //1男 2女,直接解析好
    public String birthday;  //
    public String age = " ";  //根据birthday解析age
    public String u_address;
    public boolean my_thumbsup;
    public boolean my_follow;
    public int follow_num;
    public int comment_num;
    public int hot;
    public long createtime;
    public boolean isShowDelete = false;//非服务器数据,标识是否显示删除按钮,默认为不显示

    //活动属性
    public List<HighLight> highLights;

    public Content(JSONObject object) {
        if (object != null) {
            id = object.optInt("id");
            url = object.optString("url");
            thumbnail = object.optString("thumbnail");
            type = object.optInt("type");
            title = object.optString("title");
            u_id = object.optInt("u_id");
            u_name = object.optString("u_name");
            u_headimg = object.optString("u_headimg");
            u_apply_id = object.optInt("u_apply_id");
            u_apply = object.optString("u_apply");
            u_apply_tip = object.optString("u_apply_tip", "");
            u_auth = object.optBoolean("u_auth");
            share_num = object.optInt("share_num");
            thumbsup_num = object.optInt("thumbsup_num");
            comment_num = object.optInt("comment_num");
            browse_num = object.optInt("browse_num");
            hot = object.optInt("hot");
            createtime = object.optLong("createtime");
            if (object.optInt("u_gender") == 1) {
                u_gender = "男 ";
            } else if (object.optInt("u_gender") == 2) {
                u_gender = "女 ";
            } else {
                u_gender = "性别未知 ";
            }
            birthday = object.optString("birthday", "");
            if (!birthday.equals("")) {
                birthday = birthday.substring(0, 4);
                Calendar calendar = Calendar.getInstance();
                int year = calendar.get(Calendar.YEAR);
                int birthday = StringUtil.stringToInt(age);
                int ageInt = year - birthday > 0 ? year - birthday : 0;
                age = ageInt + "岁 ";
            }
            u_address = object.optString("u_address", "");
            String place = u_address;
            if (!place.equals("")) {
                if (place.contains(",")) {
                    place = place.substring(0, place.indexOf(","));
                }
                u_address = place + " ";
            }
            my_thumbsup = object.optBoolean("my_thumbsup");
            my_follow = object.optBoolean("my_follow");
            follow_num = object.optInt("follow_num");
            status = object.optInt("status", 1); //如果没有该字段,默认审核通过
            reason = object.optString("reason", "");
            user_type = object.optString("user_type");
            //活动属性
            highLights = new ArrayList<>();
            JSONArray arr = object.optJSONArray("highlights");
            if (arr != null) {
                for (int i = 0; i < arr.length(); i++) {
                    HighLight highLight = new HighLight(arr.optJSONObject(i));
                    highLights.add(highLight);
                }
            }
        }
    }

    public int getId() {
        return id;
    }

    public String getUrl() {
        return url;
    }

    public String getThumbnail() {
        return thumbnail;
    }

    public int getType() {
        return type;
    }

    public String getTitle() {
        return title;
    }

    public int getU_id() {
        return u_id;
    }

    public String getU_name() {
        return u_name;
    }

    public String getU_headimg() {
        return u_headimg;
    }

    public int getU_apply_id() {
        return u_apply_id;
    }

    public String getU_apply() {
        return u_apply;
    }

    public boolean isU_auth() {
        return u_auth;
    }

    public int getShare_num() {
        return share_num;
    }

    public int getThumbsup_num() {
        return thumbsup_num;
    }

    public int getComment_num() {
        return comment_num;
    }

    public int getHot() {
        return hot;
    }

    public long getCreatetime() {
        return createtime;
    }
}
